/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package estg.dae.projecto.broker.model;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Properties;

/**
 *
 * @author mario
 */
public class BrokerSettings implements Serializable {

    private static String BROKER_CONF_FILE_URL = "estg/dae/projecto/broker/utils/broker.properties";
    private static BrokerSettings brokerSettings;
    private String name;
    private String address;
    private String phone;
    private String email;
    private String hostname;
    private String serviceLocation;
    private int port;

    protected BrokerSettings() {
        try {
            InputStream is = this.getClass().getClassLoader().
                    getResourceAsStream(BROKER_CONF_FILE_URL);
            Properties conf = new Properties();
            conf.load(is);

            name = conf.getProperty("broker.name");
            address = conf.getProperty("broker.address");
            phone = conf.getProperty("broker.phone");
            email = conf.getProperty("broker.email");
            hostname = conf.getProperty("broker.hostname");
            serviceLocation = conf.getProperty("broker.serviceLocation");
            port = Integer.parseInt(conf.getProperty("broker.hostport"));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static BrokerSettings getInstance() {
        if (brokerSettings == null)
            brokerSettings = new BrokerSettings();

        return brokerSettings;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the address
     */
    public String getAddress() {
        return address;
    }

    /**
     * @param address the address to set
     */
    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * @return the phone
     */
    public String getPhone() {
        return phone;
    }

    /**
     * @param phone the phone to set
     */
    public void setPhone(String phone) {
        this.phone = phone;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return the hostname
     */
    public String getHostname() {
        return hostname;
    }

    /**
     * @param hostname the hostname to set
     */
    public void setHostname(String hostname) {
        this.hostname = hostname;
    }

    /**
     * @return the serviceLocation
     */
    public String getServiceLocation() {
        return serviceLocation;
    }

    /**
     * @param serviceLocation the serviceLocation to set
     */
    public void setServiceLocation(String serviceLocation) {
        this.serviceLocation = serviceLocation;
    }

    /**
     * @return the port
     */
    public int getPort() {
        return port;
    }

    /**
     * @param port the port to set
     */
    public void setPort(int port) {
        this.port = port;
    }

}